$(function() {
    
   $('.datepicker').datepicker({format:'yyyy-mm-dd'});


    $('.employeForm #departement_id, .employeList #departement_id, .garde #departement_id').change(function() {
    	var select = $('#service_id');
        select.fadeTo(200, '0.1');
    	$.ajax({
    		url:"../ajax/ajax.php",
    		data: {
    			departementId: $(this).val(),
    		    fnc: 'getServiceByDepartementId'
    		}
    	}).done(function(result) {
            
            var options = [];
            options.push($('<option>').text('--Selectionner un service--'));
            $.each(result, function(key, obj) {
                options.push($('<option>').attr('value', obj.id).text(obj.name));
            });
            select.html(options);
            select.fadeTo(200, '1');  
    	});
    });

    $('.employeList #service_id').change(function() {
        document.location.href = document.location.href.split('?')[0] + '?service_id=' + $(this).val();
    });
    $('.serviceList #departement_id').change(function() {
        document.location.href = document.location.href.split('?')[0] + '?departement_id=' + $(this).val();
    });
    $('.employeList #type').change(function() {
        document.location.href = document.location.href.split('&')[0] + '&type=' + $(this).val();
    });
    $('.gardUnit #type').change(function() {
        document.location.href = document.location.href.split('?')[0] + '?type=' + $(this).val();
    });
});
